package com.joven.core.controller;

import com.joven.core.constant.ResultInfo;
import com.joven.core.service.TestRedisLockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author joven_wong
 * 2021/7/1 15:43
 */
@RestController
@RequestMapping("/redis")
public class TestRedisLockController {

    @Autowired
    TestRedisLockService testRedisLockService;

    @GetMapping("/test1")
    public ResultInfo getStoreNum1(){
        String result = testRedisLockService.updateCountCore("2500204303",10);
        if("success".equals(result)){
            return ResultInfo.success("购买成功");
        } else if ("wait".equals(result)){
            return ResultInfo.success("请等待");
        } else if ("sorry".equals(result)){
            return ResultInfo.success("购买失败，数额不足");
        }
        return ResultInfo.success("购买失败");
    }

    @GetMapping("/test2")
    public ResultInfo getStoreNum2(){
        String result = testRedisLockService.updateCountCore("2500204303",10);
        if("success".equals(result)){
            return ResultInfo.success("购买成功");
        } else if ("wait".equals(result)){
            return ResultInfo.success("请等待");
        } else if ("sorry".equals(result)){
            return ResultInfo.success("购买失败，数额不足");
        }
        return ResultInfo.success("购买失败");
    }

}
